import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserController } from '../user/user.controller';
import { UserModule } from '../user/user.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from '../../entities/user.entity';
import { Friendships } from '../../entities/friendships.entity'
import { AuthModule } from '../auth/auth.module';
import { ArticleModule } from '../article/article.module';
import { UploadController } from '../upload/upload.controller';
import { UploadService } from '../upload/upload.service';
import { UploadModule } from '../upload/upload.module';
import { MulterModule } from '@nestjs/platform-express'
import { diskStorage } from 'multer';
import { FriendshipsController } from '../friendships/friendships.controller';
import { FriendshipsModule } from '../friendships/friendships.module';
import { Article } from '../../entities/article.entity'
import { ArticleCover } from '../../entities/articleCover.entity'
import { ArticleCommentModule } from '../../modules/article-comment/article-comment.module'
import { ArticleMoment } from '../../entities/articleMoment.entity'
import { ArticleLike } from '../../entities/articleLike.entity'
import { ArticleLikeModule } from '../article-like/article-like.module'
import {ArticleCollectModule} from '../article-collect/article-collect.module'
import {ArticleCollect} from '../../entities/articleCollect.entity'

@Module({
  imports: [TypeOrmModule.forRoot({
    type: 'mysql',
    host: 'localhost',
    port: 3306,
    username: 'root',
    password: '88888888',
    database: 'travel_chat_db',
    entities: [User, Friendships, Article, ArticleCover, ArticleMoment, ArticleLike,ArticleCollect],
    synchronize: true,
  }),
  MulterModule.register({
    storage: diskStorage({
      destination: './uploads',
      filename: (req, file, cb) => {
        const randomSuffix = Math.floor(Math.random() * 10000)
        const ext = file.originalname.split('.').pop();
        const filename = `${Date.now()}_${randomSuffix}.${ext}`;
        cb(null, filename);
      },
    })
  }), UserModule, AuthModule, ArticleModule, UploadModule, FriendshipsModule, ArticleCommentModule,ArticleLikeModule,ArticleCollectModule],
  controllers: [AppController, UserController, UploadController, FriendshipsController],
  providers: [AppService, UploadService,],
})
export class AppModule { }
